<extend name='./Base' />
<block name='css'>
<link rel="stylesheet" href="__PUBLIC__/static/highlightJS/styles/<?php echo !isset(F('webSet')['codestyle'])?'solarized_dark':F('webSet')['codestyle'];?>.css">
<style type="text/css">code{overflow-x:auto !important;}</style>
</block>
<block name='admin-content-body'>
<div class="admin-content-body">
      <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">文章回收站</strong> / <small>Recycle</small></div>
      </div>

      <hr>

      <div class="am-g">
      <form action="{:U('__ACTION__')}" method="get">
        <div class="am-u-sm-12 am-u-md-3">
          <div class="am-form-group">
            <select data-am-selected="{btnSize: 'sm'}" name="categoryID">
              <option value=" ">所有类别</option>
              <foreach name='categories' item='v'>
              <option value="{$v['id']}" <if condition="I('get.categoryID') eq $v['id']">selected='selected'</if>>{$v['category']}</option>
              </foreach>
            </select>
          </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3">
          <div class="am-input-group am-input-group-sm">
            <input type="text" class="am-form-field" name="title" value="<?php echo $_GET['title'];?>">
          <span class="am-input-group-btn">
            <button type="submit" class="am-btn am-btn-default" type="button">搜索</button>
          </span>
          </div>
        </div>
        </form>
      </div>

      <div class="am-g">
        <div class="am-u-sm-12">
            <table class="am-table am-table-striped am-table-hover">
              <thead>
              <tr>
                <th><i class="am-icon-check-square-o"></i></th>
                <th class="table-id">ID</th>
                <th class="table-title">标题</th>
                <th class="table-type">分类</th>
                <th class="table-type">查看次数</th>
                <th class="table-type">点赞次数</th>
                <th class="table-date am-hide-sm-only">创建日期</th>
                <th class="table-date am-hide-sm-only">修改日期</th>
                <th class="table-set">操作</th>
              </tr>
              </thead>
              <tbody>
              <if condition='!empty($articles)'>
                <foreach name="articles" item='a'>
              <tr id="{$a['id']}_article">
                <td><input name="selectme" value="{$a.id}" type="checkbox"></td>
                <td>{$a['id']}</td>
                <td><a>{$a['title']|mb_substr=###,0,13,'utf-8'}...</a></td>
                <td>{$a['category']}</td>
                <td>{$a['views']}</td>
                <td>{$a['likes']}</td>
                <td class="am-hide-sm-only">{$a['create_time']|date='Y-m-d H:i',###}</td>
                <td class="am-hide-sm-only">{$a['update_time']|date='Y-m-d H:i',###}</td>
                <td>
                  <div class="am-btn-toolbar">
                    <div class="am-btn-group am-btn-group-xs">
                      <button class="am-btn am-btn-primary am-btn-xs am-text-secondary" style="color: #fff" onclick="preview({$a['id']},'{$a['title']}')"><span class="am-icon-eye"></span>预览</button>
                      <button class="am-btn am-btn-success am-btn-xs am-text-secondary" style="color: #fff" onclick="recover({$a['id']})"><span class="am-icon-undo"></span>还原</button>
                      <button class="am-btn am-btn-danger am-btn-xs am-text-secondary" style="color: #fff" onclick="deletea({$a['id']})"><span class="am-icon-trash-o"></span>删除</button>
                    </div>
                  </div>
                </td>
              </tr>
             </foreach>
             <else />
             <tr>
               <td colspan="9" style="text-align: center;">没有文章</td>
             </tr>
             </if>
              </tbody>
            </table>
            <if condition='!empty($articles)'>
            <div style="margin-top:15px" class="am-fl">
              <div class="am-btn-group">
                <button class="am-btn am-btn-default" onclick="select()">全选</button>
                <button class="am-btn am-btn-default" onclick="reverse()">反选</button>
                <button class="am-btn am-btn-default" onclick="noselect()">取消</button>
              </div>

              <div class="am-btn-group">
                <button class="am-btn am-btn-success am-text-secondary" style="color: #fff" onclick="batch(1)"><span class="am-icon-undo"></span>还原</button>
                <button class="am-btn am-btn-danger am-text-secondary" style="color: #fff" onclick="batch(0)"><span class="am-icon-trash-o"></span>删除</button>
              </div>
            </div>
            </if>
         
            <div class="am-fr">
              {$pager}
            </div>
        </div>

      </div>
    </div>

</block>

<block name="js">
<script type="text/javascript" src="__PUBLIC__/static/highlightJS/highlight.min.js"></script>
	<script type="text/javascript">

/*批量操作*/
function batch(i){
  var data={};
  $("input[name='selectme']:checked").each(function(i){
    data[i]=$(this).val();
  });
  if(JSON.stringify(data)=='{}'){
    layer.alert('请选择一些文章',{icon:5});
    return false;
  }
  if(i){
    var _url='{:U("articles/recoverAll")}';
  }else{
    if(confirm('确定要全部删除？不可恢复')){
      var _url='{:U("articles/deleteAll")}';
    }else{
      return false;
    }
  }
  $.post(_url,{'ids':data},function(res){
    if(res.status){
      $.each(data,function(index, el) {
        $("#"+el+"_article").remove();
      });
      layer.msg(res.msg);
    }else{
      layer.alert(res.msg,{icon:5});
    }
  })
}

/*删除一个*/
  function deletea(id) {
    layer.confirm('确定要删除？不可恢复！', {
        btn: ['确定','取消']
      },function(){
        $.post('{:U("articles/deletea")}',{'id':id},function(res){
          if(res.status){
            $("#"+id+"_article").remove();
            layer.msg(res.msg);
          }else{
            layer.alert(res.msg,{icon:5});
          }
        });
    },function(){})
  }
/*预览*/
    function preview(id,title){
      $.post('{:U("articles/preview")}',{'id':id},function(res){
        if(res.status){
          layer.open({
            title:'《'+title+'》正文',
            type: 1,
            // skin: 'layui-layer-rim', //加上边框
            area: ['1000px', '600px'], //宽高
            content: res.msg
          });
          setLine();
        }else{
          layer.alert(res.msg,{icon:5});
        }
      })
   }

   /*还原一个*/
   function recover(id) {
      $.post('{:U("articles/recover")}',{'id':id},function(res){
        if(res.status){
          $("#"+id+"_article").remove();
          layer.msg(res.msg);
        }else{
          layer.alert(res.msg,{icon:5});
        }
      })
   }
   /*代码高亮显示行号*/
    function setLine(){
      $('pre code').each(function(){
          var lines = $(this).text().split('\n').length - 1;
          var $numbering = $('<ul/>').addClass('pre-numbering');
          $(this)
              .addClass('has-numbering')
              .parent()
              .append($numbering);
          for(i=1;i<=lines+1;i++){
              $numbering.append($('<li/>').text(i));
          }
      });
    };
  </script>
</block>